//
//  KaiJiangDetailViewController.m
//  DaleTou
//
//  Created by hejingjin on 2018/5/29.
//  Copyright © 2018年 geren. All rights reserved.
//

#import "KaiJiangDetailViewController.h"
#import "Appearance.h"
#import "KaiJiangDetailTopTableViewCell.h"
#import "NSString+GNUtil.h"
#import "KaiJiangReatTableViewCell.h"
#import "DaletouViewController.h"

@interface KaiJiangDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableview;

@end

@implementation KaiJiangDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorWithHexString:@"ffffff"];
    [self setNavConfigStartColor:@"#ff8e01" endColor:@"#ff8e01"];
    [self ApptitileView:@"开奖结果"];
    
    if (@available(iOS 11.0, *)) {
        self.tableview.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableview];
    
    [self.tableview reloadData];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 1;
    }else{
        return 7;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 160.f;
    }else{
        return 40;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section ==0) {
        KaiJiangDetailTopTableViewCell *cell = [KaiJiangDetailTopTableViewCell cellWithTableView:tableView];
        
        for (UIButton *btm in cell.btnarray) {
            NSInteger tag = btm.tag;
            if (tag<5) {
                if (_model.redarray.count>tag) {
                    [btm setTitle:[NSString stringWithFormat:@"%@",_model.redarray[tag]] forState:UIControlStateNormal];
                }
            }else{
                if (_model.bluearray.count>tag-5) {
                    [btm setTitle:[NSString stringWithFormat:@"%@",_model.bluearray[tag -5]] forState:UIControlStateNormal];
                }
            }
        }
        cell.numberLcount.text = [NSString stringWithFormat:@"第%@期",_model.qishu];
        cell.timeLabels.text = _model.timestr;
        int x = arc4random()%23221 +212452;
        int y = arc4random()%4219278 +41258095;
        cell.currentCountLabel.text =[NSString countNumAndChangeformat:x];
        cell.allcountLabel.text =[NSString countNumAndChangeformat:y];
        return cell;
    }else{
        if (indexPath.row==0) {
            KaiJiangReatTableViewCell *cell = [KaiJiangReatTableViewCell cellWithTableView:tableView];
            for (UILabel *label in cell.labelArray) {
                label.backgroundColor = [UIColor colorWithHexString:@"FF8E01"];
                label.textColor = [UIColor colorWithHexString:@"ffffff"];
                if (label.tag==0) {
                    label.text = @"奖项";
                }else if (label.tag==1){
                     label.text = @"每注奖金";
                }else{
                     label.text = @"注数";
                }
            }
            return cell;
        }else{
            KaiJiangReatTableViewCell *cell = [KaiJiangReatTableViewCell cellWithTableView:tableView];
            
            for (UILabel *label in cell.labelArray) {
                label.backgroundColor = [UIColor colorWithHexString:@"ffffff"];
                label.textColor = [UIColor colorWithHexString:@"333333"];
                if (label.tag==0) {
                    switch (indexPath.row) {
                        case 1:
                            label.text = @"一等奖";
                            break;
                        case 2:
                            label.text = @"二等奖";
                            break;

                        case 3:
                            label.text = @"三等奖";
                            break;

                        case 4:
                            label.text = @"四等奖";
                            break;

                        case 5:
                            label.text = @"五等奖";
                            break;

                        case 6:
                            label.text = @"六等奖";
                            break;

                            
                        default:
                            break;
                    }
                
                }else if (label.tag==1){
                  
                        switch (indexPath.row) {
                            case 1:
                            {
                                int x = arc4random()%24009 +3435342;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                            case 2:
                            {
                                int x = arc4random()%14000 +335342;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                                
                            case 3:
                            {
                                int x = arc4random()%1000 +1352;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                                
                            case 4:
                                 label.text = @"200";
                                break;
                                
                            case 5:
                                label.text = @"10";
                                break;
                                
                            case 6:
                                label.text = @"5";
                                break;
                                
                                
                            default:
                                break;
                        }
                }else{
                        switch (indexPath.row) {
                            case 1:
                            {
                                int x = arc4random()%4;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                            case 2:
                            {
                                int x = arc4random()%34 +28;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                                
                            case 3:
                            {
                                int x = arc4random()%200 +213;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                                
                            case 4:
                            {
                                int x = arc4random()%2314 +1232;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                                
                            case 5:
                            {
                                int x = arc4random()%21452 +8921;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                                
                            case 6:
                            {
                                int x = arc4random()%240091 +23145;
                                label.text = [NSString stringWithFormat:@"%d",x];
                            }
                                break;
                                
                                
                            default:
                                break;
                        }
                }
            }
            return cell;
        }
        
    }

    
}




-(UITableView *)tableview{
    if (!_tableview) {
        CGRect frame = CGRectMake(0,NAV_HEIGHT, Main_Screen_Width, Main_Screen_Height-NAV_HEIGHT);
        _tableview = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.estimatedRowHeight = 0;
        _tableview.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.showsVerticalScrollIndicator = NO;
        
        UIView *footerview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 120)];
        UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(30, 40, Main_Screen_Width - 60, 40)];
        button.layer.cornerRadius = 20.f;
        button.layer.masksToBounds = YES;
        [button setTitle:@"去中奖" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
        [button setBackgroundColor:[UIColor colorWithHexString:@"FF8E01"]];
        button.titleLabel.font = [UIFont systemFontOfSize:17];
        [button addTarget: self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
        footerview.backgroundColor = [UIColor whiteColor];
        [footerview addSubview:button];
        
        _tableview.tableFooterView = footerview;
        
        
        
        
    }
    return _tableview;
}

-(void)btnPressed:(UIButton *)sender{
    DaletouViewController *vc = [[DaletouViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
